#ifndef GOAL_H
#define GOAL_H

#include <QDate>
#include <QString>
#include <QObject>

#define FORMAT_DATE "dd/MM/yy"

class MoneyGoal : public QObject
{

    Q_OBJECT
    Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
    Q_PROPERTY(int goalType READ goalType WRITE setGoalType NOTIFY goalTypeChanged)
    Q_PROPERTY(float target READ target WRITE setTarget NOTIFY targetChanged)
    Q_PROPERTY(QString initialDate READ initialDate WRITE setInitialDate NOTIFY initialDateChanged)
    Q_PROPERTY(QString finalDate READ finalDate WRITE setFinalDate NOTIFY finalDateChanged)
    Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
    Q_PROPERTY(int percentage READ percentage WRITE setPercentage NOTIFY percentageChanged)

public:
    enum goal_types {IN_greater_than, OUT_less_than, Total_greater_than};
private:
    int idGoal;
    goal_types goal_money;
    float m_target;
    QDate dtInitial;
    QDate dtFinal;
    QString m_description;
    int m_percentage;

public:
    MoneyGoal(QObject* parent = 0) : QObject(parent)
    {
        this->m_percentage = 0;
    }
    MoneyGoal(int idGoal, goal_types goal_money, float target, QDate dtInitial,QDate dtFinal, QString description, QObject* parent = 0)
        : QObject(parent)
    {
        this->idGoal = idGoal;
        this->goal_money = goal_money;
        this->m_target = target;
        this->dtInitial = dtInitial;
        this->dtFinal = dtFinal;
        this->m_description = description;
        this->m_percentage = 0;
    }

    void setId(int idGoal) { this->idGoal = idGoal;}
    void setTypeGoal(goal_types type_goal) { this->goal_money = type_goal; }
    void setTarget(float target) { this->m_target = target;}
    void setDtInitial(QDate dtInitial) { this->dtInitial = dtInitial; }
    void setDtFinal(QDate dtFinal) { this->dtFinal = dtFinal; }
    void setInitialDate(QString initialDate)
    {
        dtInitial = QDate::fromString(initialDate, FORMAT_DATE);
        dtInitial = dtInitial.addYears(100);
    }
    void setFinalDate(QString finalDate)
    {
        dtFinal = QDate::fromString(finalDate, FORMAT_DATE);
        dtFinal = dtFinal.addYears(100);
    }
    void setDescription(QString description) { m_description = description; }
    void setGoalType(int type)
    {
        if (type == 0)
            goal_money = IN_greater_than;
        else if (type == 1)
            goal_money = OUT_less_than;
        else goal_money = Total_greater_than;
    }
    void setPercentage(int percentage) { m_percentage = percentage; }

    int getId() { return idGoal; }
    goal_types getTypeGoal() { return goal_money; }
    float getTarget() { return m_target; }
    QDate getDtInitial() { return dtInitial; }
    QDate getDtFinal() { return dtFinal; }

    int id() { return idGoal; }
    int goalType()
    {
        if (goal_money == IN_greater_than)
            return 0;
        else if (goal_money == OUT_less_than)
            return 1;
        return 2;
    }
    float target() { return m_target;}
    QString initialDate() { return dtInitial.toString(FORMAT_DATE); }
    QString finalDate() { return dtFinal.toString(FORMAT_DATE); }
    QString description() { return m_description; }
    int percentage() { return m_percentage; }

signals:
    void idChanged();
    void goalTypeChanged();
    void targetChanged();
    void initialDateChanged();
    void finalDateChanged();
    void descriptionChanged();
    void percentageChanged();

};

#endif // GOAL_H
